<template>
  <el-dialog :title="title" :visible.sync="openAudit" width="800px" append-to-body>
    <el-form ref="formAudit" :model="formAudit" label-width="80px">
      <el-form-item label="名称" prop="name">
        <el-input v-model="formAudit.name" placeholder="请输入名称" disabled/>
      </el-form-item>
      <el-form-item label="文件" prop="file">
        <file-upload v-model="formAudit.file" :limit=1 :fileSize=500 :fileType='["zip", "docx", "xlsx", "pptx", "txt", "pdf"]' :data='{profile:"res"}' disabled/>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="formAudit.password" placeholder="请输入密码" disabled/>
      </el-form-item>
      <el-form-item label="话术" prop="speak">
        <editor v-model="formAudit.speak" :speak = "true" :min-height="192" disabled/>
      </el-form-item>
      <el-form-item label="审核状态" prop="auditStatus">
        <el-select v-model="formAudit.auditStatus" placeholder="请选择审核状态" clearable>
          <el-option
            v-for="dict in dict.type.audit_status"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核备注" prop="auditRemark" v-if="formAudit.auditStatus==2">
        <el-input v-model="formAudit.auditRemark" placeholder="请输入审核备注" type="textarea"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitFormAudit">确 定</el-button>
      <el-button @click="cancelAudit">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { auditProductRes } from "@/api/supermarket/productRes";

export default {
  name: "AuditProductResForm",
  dicts: ['audit_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "",
      // 是否显示审核弹出层
      openAudit: false,
      // 表单参数
      formAudit: {},
    };
  },
  methods: {
    /** 审核按钮操作 */
    handleAudit(row) {
      this.resetAudit();
      this.formAudit.name = row.name;
      this.formAudit.uuid = row.uuid;
      this.formAudit.file = row.file;
      this.formAudit.password = row.password;
      this.formAudit.speak = row.speak;
      this.formAudit.auditStatus = row.auditStatus;
      this.formAudit.auditRemark = row.auditRemark;
      this.title = "审核商品资源信息";
      this.openAudit = true;
    }, 
    /** 提交审核按钮 */
    submitFormAudit() {
      this.loading = true;
      if(this.formAudit.auditStatus == 1){
        this.formAudit.auditRemark = "审核通过";
      }
      auditProductRes(this.formAudit).then(response => {
        this.$parent.getList();
        this.resetAudit();
        this.loading = false;
        this.openAudit = false;
      });
    },
    // 取消按钮
    cancelAudit() {
      this.openAudit = false;
      this.resetAudit();
    },
    // 重置审核表单
    resetAudit() {
      this.formAudit = {
        name: null,
        uuid: null,
        file: null,
        password: null,
        speak: null,
        auditStatus: null,
        auditRemark: null
      };
      this.resetForm("formAudit");
    },
  }
}
</script>